<?php
namespace app\student\controller;
use app\common\Base;
use app\common\StudentModel;
use think\Db;

class StudentZczr extends Base {
	
	public function index() {
		return $this->fetch();
	}

	public function pageQuery() {
		$grade = input("grade");
		$clazz = input("clazz");
		$name = input("studentName");
		$schoolStatus = input("schoolStatus");
		$page = input("page");
		$rows = input("rows");
		$sort = input("sort");
		$order = input("order");
		$orderby = null;
		if($sort) {
			$orderby = $sort." ".$order;
		}
		$where["年级号"] = array("gt", currTerm()["finishedKey"]);
		if($grade) {
			$array = explode("_", $grade);
			$where["年级号"] = array("eq", $array[0]);
			$where["学籍类型"] = array("eq", $array[1]);
		}
		if($clazz) $where["班号"] = array("eq", $clazz);
		if($name) $where["姓名"] = array("like", $name."%");
		if($schoolStatus) {
			if($schoolStatus == "0") $where["转出学期ID"] = array("eq", 0);
			else $where["转出学期ID"] = array("gt", 0);
		}
		$fields = ["ID,年级号,班号,学号,姓名,学籍类型,转出学期ID"];
		$Model = new StudentModel();
		return $Model->getStudentList($page, $rows, $fields, $where, $orderby);
	}

	public function zczr() {
		try {
			$ID = input("ID");
			$type = input("type");
			$where["ID"] = $ID;
			if($type == '0') {
				$where["转出学期ID"] = $type;
				$where["转入学期ID"] = currTerm()["termId"];
			}else {
				$where["转出学期ID"] = currTerm()["termId"];
			}
			update('学生信息', $where);
			return '000';
		} catch (Exception $e) {
			echo $e->getMessage();
		}
		return "999";
	} 

}
